#include <stdio.h>
#include <stdlib.h>
#include "cJSON.h"
#include <math.h>

int main()
{
    char *jsonText = "{\"name\":\"nick\",\"age\":18,\"isMarried\":false,\"addr\":{\"city\":\"beijing\",\"street\":\"dongdajie\"},\"skill\":[\"world\",\"cjson\"]}";

    cJSON *root = cJSON_Parse(jsonText);

    cJSON *name = cJSON_GetObjectItem(root, "name");
    printf("name:%s\n", name->valuestring);

    cJSON *age = cJSON_GetObjectItem(root, "age");
    printf("age:%d\n", age->valueint);

    cJSON *isMarried = cJSON_GetObjectItem(root, "isMarried");
    printf("isMarried:%d\n", isMarried->valueint);

    cJSON *addr = cJSON_GetObjectItem(root, "addr");
    printf("city:%s\n", cJSON_GetObjectItem(addr, "city")->valuestring);
    printf("street:%s\n", cJSON_GetObjectItem(addr, "street")->valuestring);

    cJSON *skill = cJSON_GetObjectItem(root, "skill");

    int len = cJSON_GetArraySize(skill);
    for (int i = 0; i < len; i++)
    {
        printf("skill[%d]:%s\n", i, cJSON_GetArrayItem(skill, i)->valuestring);
    }

    return 0;
}

/*

{

    "name":"nick",
    "age":18,
    "isMarried":false,
    "addr": {
        "city": "beijing",
        "street":"dongdajie"
    },
    "skill":["world","cjson"]
}


*/